//
//  ChangeAlertView.m
//  League
//
//  Created by 崔璨 on 2018/1/25.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "ChangeAlertView.h"
#import "BaseViewController.h"
#define kBKColor [UIColor colorWithRed:243/255.0 green:242/255.0 blue:243/255.0 alpha:1]

#define kCancelTextColor [UIColor colorWithRed:190/255.0 green:190/255.0 blue:190/255.0 alpha:1]
@implementation ChangeAlertView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame=frame;
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
        [self setupUI];
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeView)];
        singleTap.delegate=self;
        [self addGestureRecognizer:singleTap];
    }
    return self;
}
-(void)setupUI
{
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width*0.8, self.height/2)];
    self.bgView.center = CGPointMake(self.width/2, self.height/2);
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 8;
    [self addSubview:self.bgView];
    
    self.headLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height/4)];
    self.headLab.font=[UIFont fontWithName:kFontName size:self.headLab.height/4];
    self.headLab.textAlignment = NSTextAlignmentCenter;
    [self.bgView addSubview: self.headLab];
    
    self.textFileOne = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width*0.9, self.bgView.height/6)];
    self.textFileOne.center = CGPointMake(self.bgView.width/2, self.headLab.y+self.headLab.height+self.textFileOne.height/2);
    self.textFileOne.font = [UIFont fontWithName:kFontName size:self.textFileOne.height/2];
    self.textFileOne.textAlignment = NSTextAlignmentCenter;
    self.textFileOne.layer.masksToBounds = YES;
    self.textFileOne.layer.cornerRadius = 8;
    self.textFileOne.layer.borderWidth = 2;
    self.textFileOne.layer.borderColor = [kBKColor CGColor];
    [self.bgView addSubview:self.textFileOne];
    
    self.textFileTwo = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width*0.9, self.bgView.height/6)];
    self.textFileTwo.center = CGPointMake(self.bgView.width/2, self.textFileOne.y+self.textFileOne.height+self.textFileTwo.height/2+5);
    self.textFileTwo.font = [UIFont fontWithName:kFontName size:self.textFileOne.height/2];
    self.textFileTwo.textAlignment = NSTextAlignmentCenter;
    self.textFileTwo.layer.masksToBounds = YES;
    self.textFileTwo.layer.cornerRadius = 8;
    self.textFileTwo.layer.borderWidth = 2;
    self.textFileTwo.layer.borderColor = [kBKColor CGColor];
    [self.bgView addSubview:self.textFileTwo];
    
    self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height/7)];
    self.cancelBtn.center = CGPointMake(self.bgView.width/2, self.bgView.height - self.cancelBtn.height/2);
//    self.cancelBtn.backgroundColor = [UIColor redColor];
    [self.cancelBtn setTitleColor:kCancelTextColor forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = [UIFont fontWithName:kFontName size:self.cancelBtn.height/2.5];
    [self.cancelBtn addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchDown];
    [self.bgView addSubview:self.cancelBtn];
    
    
    self.changeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height/7)];
    self.changeBtn.center = CGPointMake(self.bgView.width/2, self.cancelBtn.y-self.changeBtn.height/2);
    [self.changeBtn setTitleColor:kAppColor forState:UIControlStateNormal];
//    self.changeBtn.backgroundColor = [UIColor yellowColor];
    self.changeBtn.titleLabel.font = [UIFont fontWithName:kFontName size:self.changeBtn.height/2.5];
    [self.bgView addSubview:self.changeBtn];
    
    
    
    self.lineOne = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 1)];
    self.lineOne.center = CGPointMake(self.bgView.width/2, self.cancelBtn.y-self.lineOne.height/2);
    self.lineOne.backgroundColor = kBKColor;
    [self.bgView addSubview:self.lineOne];
    
    
    self.lineTwo = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 1)];
    self.lineTwo.center = CGPointMake(self.bgView.width/2, self.changeBtn.y-self.lineTwo.height/2);
    self.lineTwo.backgroundColor = kBKColor;
    [self.bgView addSubview:self.lineTwo];
    
    
}
-(void)removeView
{
    [self removeFromSuperview];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    
    if (touch.view !=self){
        
        return NO;
        
    }
    
    return YES;
    
}
@end
